<template>
	<s-layout class="wallet-wrap" title="分享" :navbar="'normal'" :bgStyle="{ color: '#fff' }" onShareAppMessage>
		<s-empty v-if="state.pagination.total === 0" text="暂无数据" icon="/static/data-empty.png" />
		<!-- 钱包记录 -->
		<view v-if="state.pagination.total > 0">
			<view class="wallet-list ss-flex border-bottom ss-m-x-30 ss-m-b-20 ss-m-t-14" v-for="item in state.pagination.data"
				:key="item.id" @tap.stop="toShare(item.id)">
				<view class="list-content">
					<view class="title-box"> 
						<image class="logo" :src="sheep.$url.cdn(item.image)" mode=""></image>
					</view>
					<view class="title-box ss-m-20">
						{{item.blurb}}
					</view>
				</view>
			</view>
		</view>
		<uni-load-more v-if="state.pagination.total > 0" :status="state.loadStatus" :content-text="{
        contentdown: '上拉加载更多',
      }" />
	</s-layout>
</template>

<script setup>
	import {
		computed,
		watch,
		reactive
	} from 'vue';
	import {
		onLoad,
		onReachBottom
	} from '@dcloudio/uni-app';
	import sheep from '@/sheep';
	import dayjs from 'dayjs';
	import _ from 'lodash';

	const headerBg = sheep.$url.css('/assets/addons/shopro/uniapp/user/wallet_card_bg.png');

	const pagination = {
		data: [],
		current_page: 1,
		total: 1,
		last_page: 1,
		expense: 0,
		income: 0,
	};
	// 数据
	const state = reactive({
		date: [],
		pagination,
		loadStatus: '',
	});

	const userInfo = computed(() => sheep.$store('user').userInfo);

	async function getList(page = 1, list_rows = 8) {
		state.loadStatus = 'loading';
		let res = await sheep.$api.commission.informationList({
			list_rows,
			page,
		});
		if (res.code === 1) {
			state.pagination.data = _.concat(state.pagination.data, res.data.data);
			if (state.pagination.current_page < state.pagination.last_page) {
				state.loadStatus = 'more';
			} else {
				state.loadStatus = 'noMore';
			}
		}
	}
	onLoad(async (options) => {
		getList();
	});

	onReachBottom(() => {
		if (state.loadStatus !== 'noMore') {
			getList(state.pagination.current_page + 1);
		}
	});
	function toShare(id){
		uni.navigateTo({
			url:`/pages/user/wallet/shareDetails?id=${id}`
		})
	}
</script>

<style lang="scss" scoped>
	.wallet-wrap {
		height: 100vh;
	}

	.wallet-list {
		box-shadow: 0 0 8rpx 8rpx #f3f3f4;
		background-color: #ffff;
		
		.logo {
			width: 690rpx;
			max-height:480rpx;
			// height: 360rpx;
		}

		.list-content {
			border-radius: 20rpx;
			
			.title {
				font-size: 28rpx;
				color: $dark-3;
			}
		}
	}
</style>